<template>
  <div class="app-container">
    <div class="head-container">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item name="1">
          <template slot="title">
            <i class="el-icon-search" />搜索栏
          </template>
          <el-form :model="params" class="searchform" :inline="true" size="mini" label-width="auto">
            <el-form-item label="模板类型">
              <el-select v-model="params.changeType" placeholder="选择搜索" clearable style="width: 200px">
                <el-option v-for="option in templateConfig.changeType" :key="option.key" :label="option.value" :value="option.key" />
              </el-select>
            </el-form-item>
            <el-form-item label="模板用途">
              <el-select v-model="params.templateType" placeholder="选择搜索" clearable style="width: 200px">
                <el-option v-for="option in templateConfig.templateType" :key="option.key" :label="option.value" :value="option.key" />
              </el-select>
            </el-form-item>
            <el-form-item label="上传人ID">
              <el-input v-model="params.createdBy" placeholder="输入USER_ID查询" clearable style="width: 200px;" />
            </el-form-item>
            <el-form-item label="上传时间">
              <el-date-picker
                v-model="syncTime"
                type="datetimerange"
                value-format="yyyy/MM/dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="syncTimeChange"
              />
            </el-form-item>
            <el-form-item>
              <el-button size="mini" type="primary" style="float:right;margin-right:0px;" icon="el-icon-refresh" round @click="resetForm">重置</el-button>
              <el-button size="mini" type="primary" style="float:right;margin-right:0px;" icon="el-icon-search" round @click="toQuery">查询</el-button>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
    <div style="padding-top:5px">
      <el-button size="mini" type="primary" style="float:right;margin-bottom:5px;margin-left:0px;" icon="el-icon-circle-plus" round @click="doAddTemplate">导入模板</el-button>
      <el-table ref="itemTab" :data="data" stripe size="small" border style="width: 100%;" @header-dragend="colChange">
        <el-table-column :show-overflow-tooltip="true" label="模板类型" prop="changeType" :width="colWidths.changeType">
          <template slot-scope="scope">
            <div v-for="option in templateConfig.changeType" :key="option.key">
              <span v-if="scope.row.changeType === option.key">{{ option.value }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="模板用途" prop="templateType" :width="colWidths.templateType">
          <template slot-scope="scope">
            <div v-for="option in templateConfig.templateType" :key="option.key">
              <span v-if="scope.row.templateType === option.key">{{ option.value }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="模板文件" prop="templateUrl" :width="colWidths.templateUrl">
          <template slot-scope="scope">
            <i v-if="scope.row.templateUrl" class="el-icon-picture" style="font-size:23px;margin-right: 3px;" @click="previewFile(scope.row.templateUrl)" />
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="上传人ID" prop="createdBy" :width="colWidths.createdBy" />
        <el-table-column :show-overflow-tooltip="true" label="上传时间" prop="createdTime" :width="colWidths.createdTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createdTime) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <el-pagination
        :total="total"
        :current-page.sync="currentPage"
        :page-sizes="[10,50,100,500]"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"
      />
    </div>
    <fileForm ref="fileForm" :parent="parent" />
  </div>
</template>

<script>
import { previewFile } from '@/utils/item'
import initData from '@/utils/initData'
import fileForm from './file'
import { parseTime } from '@/utils/index'

export default {
  components: { fileForm },
  mixins: [initData],
  data() {
    return {
      syncTime: [],
      parent: this,
      activeName: '1',
      templateConfig: window.templateConfig
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    previewFile,
    parseTime,
    beforeInit() {
      this.url = '/exportTemplate/queryList'
      this.params.pageNum = this.page
      this.params.pageSize = this.size
      return true
    },
    // 查询
    toQuery() {
      this.page = 0
      this.currentPage = 1
      this.init()
    },
    // 查询栏重置触发
    resetForm() {
      this.syncTime = []
      this.params = {}
    },
    // 点击导入按钮触发
    doAddTemplate() {
      this.$refs.fileForm.dialog = true
    },
    // 上传时间日期组件触发
    syncTimeChange(val) {
      this.params.findCreatedTimeStart = val[0]
      this.params.findCreatedTimeEnd = val[1]
    }
  }
}
</script>

